<?php
namespace app\beautiful\model\project;
use app\common\model\CommonModel;

class SnapUpModel extends CommonModel{
    protected  $name = 'beautiful_snap_up';
    protected  $pk   = 'snap_up_id';

    protected $type=[
        'rotation'=>'array',
        'snap_up_details'=>'array'
    ];

    public function type()
    {
        return $this->hasOne(ProjectTypeModel::class,'project_type_id','project_type_id');
    }

    public function project()
    {
        return $this->hasOne(ProjectModel::class,'project_id','project_id');
    }

    public function getFlashSaleTimeAttr($value,$data)
    {
        return [$data['start_time'],$data['end_time']];
    }
    
    public function getFlashSaleDjsAttr($value,$data){
        $end_time = strtotime($data['end_time']) + 86400;
        $t = $end_time - time();
        return $t > 0 ? $t : 0;
    }
    
    public function getIsFlashSaleExpireAttr($value,$data)
    {
        $today=date("Y-m-d");
        if($data['start_time']<=$today && $data['end_time']>=$today && $data['flash_num']>0){
            return 0;
        }else{
            return 1;
        }
    }

}
